﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientAppViaWebService.LaboratoriesLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class LaboratoryEditForm : ResearchDivisionEditForm
    {
        private LaboratoriesLogicService lService;
        private readonly Int32 ClassID = 4;

        public LaboratoryEditForm()
        {
            InitializeComponent();
            lService = new LaboratoriesLogicService();
            classTextBox.Text = ClassID.ToString();
        }

        public String WorkingHours
        {
            get { return workingHoursTextBox.Text; }
            set { workingHoursTextBox.Text = value; }
        }

        protected override void SetFormProperties(Object _object)
        {
            Laboratory d = (_object as Laboratory);
            ID = d.ID;
            EXT_ID = d.EXT_ID;
            ParentId = d.PARENT_ID;
            Class = d.CLASS_ID;
            ObjName = d.NAME;
            BossName = d.BOSS_ID;
            DateCreated = d.DATE_CREATED;
            Description = d.DESCRIPTION;
            Financing = d.FINANCING;
            Sponsors = d.SPONSORS;
            Purpose = d.PURPOSE;
            Awards = d.AWARDS;
            WorkingHours = d.WORKING_HOURS;
        }

        protected override Object RetrieveFormProperties()
        {
            Laboratory lab = new Laboratory();
            lab.ID = ID;
            lab.EXT_ID = EXT_ID;
            lab.PARENT_ID = ParentId;
            lab.CLASS_ID = Class;
            lab.NAME = ObjName;
            lab.DataBaseName = DataBaseName;
            lab.BOSS_ID = BossName;
            lab.DATE_CREATED = DateCreated;
            lab.DESCRIPTION = Description;
            lab.FINANCING = Financing;
            lab.SPONSORS = Sponsors;
            lab.PURPOSE = Purpose;
            lab.AWARDS = Awards;
            lab.WORKING_HOURS = WorkingHours;
            return lab;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {
            Laboratory p = lService.SelectLaboratory_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {
            Laboratory obj = RetrieveFormProperties() as Laboratory;
            lService.UpdateLaboratory(obj);
        }

        protected override void InsertEntity()
        {
            Laboratory obj = RetrieveFormProperties() as Laboratory;
            lService.InsertLaboratory(obj);
        }
    }
}
